import Vue from 'vue'
import App from './App'
import uniCrazyRouter from "uni-crazy-router";
Vue.use(uniCrazyRouter)
uniCrazyRouter.beforeEach(async (to, from ,next)=>{
    // 逻辑代码
	var flag=false;
	// alert(to.url)
	if(getApp().globalData.type=='outside'){
		if(!to.url.endsWith('pages/login/login')){
			console.log("无需登录，直接跳转->",to)
			next()
		}
		return
	}
	if(to.url.endsWith('pages/login/login') || from.url.endsWith('pages/login/login') || from.url.endsWith('pages/index/splash')||to.url.endsWith('pages/index/indexnew'||to.url=='pages/index/splash')){
		next()
	}else{
		// 拦截路由，并且跳转去其他页面
		var p = new Promise(function(resolve, reject){
			//做一些异步操作
			uni.getStorage({
				key:'userinfo',
				success:function(res){
					flag=true;
					resolve(flag);
				},
				fail() {
					if(to.url.endsWith('pages/login/login')){
						flag=true
					}else{
						flag=false
					}
					resolve(flag);
				}
			})
		}).then(function resolve(flag){
			if(flag){
				next()
			}else{
				uniCrazyRouter.afterNotNext(() => {
					uni.navigateTo({
						url: '/pages/login/login'
					})
				})
			}
		})
		
		 
		
		
		
		
	}
})

uniCrazyRouter.afterEach((to, from)=>{
    // 逻辑代码
	// alert("after")
})

uniCrazyRouter['on'+'Error']((to, from)=>{
    // 逻辑代码
	alert("error")
	// uni.navigateTo({
	//     url: '/pages/login/login'
	// })
	
})



import basics from './pages/basics/home.vue'
Vue.component('basics',basics)

import components from './pages/component/home.vue'
Vue.component('components',components)

import plugin from './pages/plugin/home.vue'
Vue.component('plugin',plugin)

//constant
import api from './constant.js'
Vue.prototype.$constant = api


import empinfo from './pages/component/empinfo.vue'
Vue.component('empinfo',empinfo)


import indexesnew from './pages/plugin/indexesnew.vue'
Vue.component('indexesnew',indexesnew)



import cuCustom from './colorui/components/cu-custom.vue'
Vue.component('cu-custom',cuCustom)

Vue.config.productionTip = false

App.mpType = 'app'



const app = new Vue({
    ...App
})


app.$mount()

 



